<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>管理员列表</title>
    <link rel="shortcut icon" href="favicon.ico">
    <link href="__CSS__/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="__CSS__/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="__CSS__/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="__CSS__/animate.min.css" rel="stylesheet">
    <link href="__CSS__/style.min.css?v=4.1.0" rel="stylesheet">
    <link href="__CSS__/plugins/sweetalert/sweetalert.css" rel="stylesheet">
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <!-- Panel Other -->
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>节点信息</h5>
        </div>
        <div class="ibox-content">
            <div class="form-group">
                {if authCheck('coupon/indexsend')}
                    <button class="btn btn-outline btn-primary" type="button" id="addNode">发优惠券</button>
                {/if}
                <!-- <button class="btn btn-outline btn-success" type="button" onclick="window.location.reload();">刷新树</button> -->
            </div>

            <div class="ibox-content">
                <div class="col-sm-6">
                    <ul id="tree"></ul>
                </div>
                <div class="col-sm-6">
                    <div id="event_output"></div>
                </div>

                <div class="clearfix"></div>
            </div>
        </div>
    </div>
</div>
    <div class="ibox-content" id="node_box" style="display: none">
    <form class="form-horizontal m-t" method="post" action="{:url('coupon/indexSend')}" id="addForm">
        <input type="hidden" class="form-control" value="1" name="type_id" id="type_id">

        <div class="form-group">
            <label class="col-sm-3 control-label">优惠券类型：</label>
            <div class="input-group col-sm-7">
                <input id="coupon_type" type="text" class="form-control" name="coupon_type" value="停车券" disabled>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">代理商：</label>
            <div class="input-group col-sm-7">
                <select class="form-control" name="company" required="" aria-required="true" id="company">
                   {if !empty($company)}
                        {foreach name="company" item="vo"}
                            <option value="{$vo.id}">{$vo.name}</option>
                        {/foreach}
                    {/if}
                </select>
            </div>
        </div>
        
        <div class="form-group">
            <label class="col-sm-3 control-label">停车券数量：</label>
            <div class="input-group col-sm-7">
                <input id="number" type="text" class="form-control" name="number" placeholder="请输入数量" required="">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">手机号：</label>
            <div class="input-group col-sm-7">
                <textarea id="phone" type="text" class="form-control" name="phone" placeholder="请输入手机号 用英文的逗号隔开" required=""></textarea>
            </div>
        </div>

        <div class="form-group">
            <div class="col-sm-4 col-sm-offset-8">
                <button class="btn btn-primary" type="submit">提交</button>
            </div>
        </div>
    </form>
</div>

            <!-- <div class="ibox-content">
                <div class="col-sm-6">
                                <ul id="tree"></ul>
                            </div>
                            <div class="col-sm-6">
                                <div id="event_output"></div>
                            </div>

                            <div class="clearfix"></div>
                        </div> -->
            <!--  <div class="form-group clearfix col-sm-1">
                {if authCheck('coupon/useradd') }
                <a href="{:url('coupon/userAdd')}">
                    <button class="btn btn-outline btn-primary" type="button">添加代理</button>
                </a>
                {/if}
            </div> -->
        <div class="ibox-content">
            <!--搜索框开始-->
            <form id='commentForm' role="form" method="post" class="form-inline pull-right">
                <div class="content clearfix m-b">
                    <div class="form-group">
                        <label>管理员名称：</label>
                        <input type="text" class="form-control" id="username" name="user_name">
                    </div>
                    <div class="form-group">
                        <button class="btn btn-primary" type="button" style="margin-top:5px" id="search"><strong>搜 索</strong>
                        </button>
                    </div>
                </div>
            </form>
            <!--搜索框结束-->
            <div class="example-wrap">
                <div class="example">
                    <table id="cusTable">
                        <thead>
                        <th data-field="id">序号</th>
                        <th data-field="car_number">车牌号</th>
                        <th data-field="park_name">用户姓名</th>
                        <th data-field="park_phone">用户手机</th>
                        <th data-field="show_order_time">预约时间</th>
                        <th data-field="day">停车天数</th>
                        <th data-field="show_end_time">到期时间</th>
                        <th data-field="show_order_price">具体费用(元)</th>
                        <th data-field="show_type">停车场类型</th>
                        <th data-field="bname">停车场名称</th>
                        </thead>
                    </table>
                </div>
            </div>
            <!-- End Example Pagination -->
        </div>
<!-- End Panel Other -->
</div>
<script src="__JS__/jquery.min.js?v=2.1.4"></script>
<script src="__JS__/bootstrap.min.js?v=3.3.6"></script>
<script src="__JS__/content.min.js?v=1.0.0"></script>
<script src="__JS__/plugins/bootstrap-table/bootstrap-table.min.js"></script>
<script src="__JS__/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
<script src="__JS__/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
<script src="__JS__/plugins/suggest/bootstrap-suggest.min.js"></script>
<script src="__JS__/plugins/layer/laydate/laydate.js"></script>
<script src="__JS__/plugins/sweetalert/sweetalert.min.js"></script>
<script src="__JS__/plugins/layer/layer.min.js"></script>
<!-- End Panel Other -->
<script src="__JS__/layui/layui.js"></script>
<script src="__JS__/jquery.form.js"></script>
<script type="text/javascript">
    function initTable() {
        //先销毁表格
        $('#cusTable').bootstrapTable('destroy');
        //初始化表格,动态从服务器加载数据
        $("#cusTable").bootstrapTable({
            method: "get",  //使用get请求到服务器获取数据
            url: "./parklist", //获取数据的地址
            striped: true,  //表格显示条纹
            pagination: true, //启动分页
            pageSize: 10,  //每页显示的记录数
            pageNumber:1, //当前第几页
            pageList: [5, 10, 15, 20, 25],  //记录数可选列表
            sidePagination: "server", //表示服务端请求
            paginationFirstText: "首页",
            paginationPreText: "上一页",
            paginationNextText: "下一页",
            paginationLastText: "尾页",
            queryParamsType : "undefined",
            queryParams: function queryParams(params) {   //设置查询参数
                var param = {
                    pageNumber: params.pageNumber,
                    pageSize: params.pageSize,
                    searchText:$('#username').val()
                };
                return param;
            },
            onLoadSuccess: function(res){  //加载成功时执行
                if(111 == res.code){
                    window.location.reload();
                }
                layer.msg("加载成功", {time : 1000});
            },
            onLoadError: function(){  //加载失败时执行
                layer.msg("加载数据失败");
            }
        });
    }


    $(document).ready(function () {
        //调用函数，初始化表格
        initTable();

        //当点击查询按钮的时候执行
        $("#search").bind("click", initTable);

    $(function(){
        // var coupon = {{$coupon}};
        $("#addNode").click(function(){
            $("#type_id").val();
            $("#company").val();
            $("#number").val();
            $("#phone").val();

            layui.use('layer', function(){
                box = layer.open({
                    type: 1,
                    title: '添加顶级节点',
                    anim: 2,
                    skin: 'layui-layer-molv', //加上边框
                    area: ['620px', '440px'], //宽高
                    content: $('#node_box')
                });
            });
        });

    // $("#addsubNode").click(function(){
    //     layer.close(box);
    //     $('#show_pid').val(nowNode.name);
    //     $('#pid').val(nowNode.id);
    //     $("#control_name").val('');
    //     $("#action_name").val('');

    //     layui.use('layer', function(){
    //         box = layer.open({
    //             type: 1,
    //             title: '添加 ' + nowNode.name + ' 的子菜单',
    //             anim: 2,
    //             skin: 'layui-layer-molv', //加上边框
    //             area: ['620px', '440px'], //宽高
    //             content: $('#node_box')
    //         });
    //     });
    // });

    // $("#editNode").click(function(){
    //     layer.close(box);
    //     $("#id").val(nowNode.id);
    //     $("#e_node_name").val(nowNode.name);
    //     $("#e_control_name").val(nowNode.control_name);
    //     $("#e_action_name").val(nowNode.action_name);
    //     $("#e_style").val(nowNode.style);

    //     var _option1 = '<option value="1" selected>否</option><option value="2">是</option>';
    //     var _option2 = '<option value="1">否</option><option value="2" selected>是</option>';
    //     if(1 == nowNode.is_menu){
    //         $("#e_is_menu").html(_option1);
    //     }else{
    //         $("#e_is_menu").html(_option2);
    //     }

    //     layui.use('layer', function(){
    //         box = layer.open({
    //             type: 1,
    //             title: '编辑  ' + nowNode.name + '  节点',
    //             anim: 2,
    //             skin: 'layui-layer-molv', //加上边框
    //             area: ['620px', '400px'], //宽高
    //             content: $('#edit_box')
    //         });
    //     });
    // });

    // $("#delNode").click(function(){
    //     layer.close(box);
    //     if(nowNode.children.length > 0){
    //         layer.alert('该节点下有子节点，不可删除', {icon:2, title:'失败提示', closeBtn:0, anim:6});
    //         return false;
    //     }

    //     //询问框
    //     var index = layer.confirm('确定要删除' + nowNode.name + '？', {
    //         icon: 3,
    //         title: '友情提示',
    //         btn: ['确定','取消'] //按钮
    //     }, function(){

    //         $.getJSON(node_del_url, {id : nowNode.id},function(res){
    //             layer.close( index );
    //             if( 1 == res.code ){
    //                 $("#tree").empty();
    //                 getTree();
    //             }else if(111 == res.code){
    //                 window.location.reload();
    //             }else{
    //                 layer.alert(res.msg, {icon:2});
    //             }
    //         });
    //     }, function(){

    //     });
    // });


            // 添加节点
            var options = {
                beforeSubmit:showStart,
                success:showSuccess
            };

            $('#addForm').submit(function(){
                $(this).ajaxSubmit(options);
                return false;
            });

            // 编辑节点
            $('#editForm').submit(function(){
                $(this).ajaxSubmit(options);
                return false;
            });
        });
    });
        // 添加相关的 js
    var index = '';
    function showStart(){
        index = layer.load(0, {shade: false});
        return true;
    }

    function showSuccess(res){
        layui.use('layer', function(){
            var layer = layui.layer;

            layer.ready(function(){
                if( 1 == res.code ){
                layer.close( index );
                layer.close( box );
                    initTable();
                }else if(111 == res.code){
                layer.close( index );
                layer.close( box );
                    window.location.reload();
                }else{
                    layer.alert(res.msg, {icon:2});
                }
            });
        });
    }

    function userEdit(id,status){
        var notice_msg = '';
        if(status == 1){
            notice_msg = '确认禁用理员?';
            status = 2;
        }else{
            notice_msg = '确认启用理员?';
            status = 1;
        }
        layer.confirm(notice_msg, {icon: 3, title:'提示'}, function(index){
            //do something
            $.getJSON("{:url('coupon/userEdit')}", {'id' : id,'status':status}, function(res){
                if(1 == res.code){
                    layer.alert(res.msg, {title: '友情提示', icon: 1, closeBtn: 0}, function(){
                        initTable();
                    });
                }else if(111 == res.code){
                    window.location.reload();
                }else{
                    layer.alert(res.msg, {title: '友情提示', icon: 2});
                }
            });

            layer.close(index);
        })
    };


</script>
</body>
</html>
